package com.system.runtai.controller;


import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.system.common.result.Result;
import com.system.runtai.entity.*;
import com.system.runtai.service.AppletUserService;
import com.system.runtai.service.IpaCollectService;
import com.system.runtai.service.IpaEnterService;
import com.system.runtai.service.IpaService;
import com.system.runtai.utils.AuthContextUtil;
import com.system.runtai.utils.IpaDown;
import com.system.runtai.utils.PromptInformationDown;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 通讯录入驻 前端控制器
 * </p>
 *
 * @author runtai
 * @since 2024-04-13
 */
@Api(tags = "通讯录入驻")
@RestController
@RequestMapping("/runtai/ipa-enter")
public class IpaEnterController {

    @Autowired
    private IpaService ipaService;

    @Autowired
    private IpaEnterService ipaEnterService;

    @Autowired
    private AppletUserService appletUserService;

    @Autowired
    private IpaCollectService ipaCollectService;

    @ApiOperation(value = "查询所有通讯录入驻(最新推荐)")
    @GetMapping("/ipaEnterListPass")
    public Result<IPage<IpaEnter>> ipaEnterListPass(Integer type,
                                                    @RequestParam(required = false) String name, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit) {
        if (type == 1) {
            if (StringUtils.isEmpty(name)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getCreateTime);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getCreateTime).like(IpaEnter::getName, name);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        } else if (type == 2) {
            if (StringUtils.isEmpty(name)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getCreateTime);
                List<IpaEnter> list = ipaEnterService.list(wrapper);
                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getCreateTime).like(IpaEnter::getName, name);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        } else if (type == 3) {
            if (StringUtils.isEmpty(name)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getCreateTime);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getCreateTime).like(IpaEnter::getName, name);
                List<IpaEnter> list = ipaEnterService.list(wrapper);


                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        }

        Page<IpaEnter> recommendPage = new Page<>(page, limit);
        IPage<IpaEnter> iPage = null;
        return Result.fail(iPage).message("查询失败！数据为空！");
    }


    @ApiOperation(value = "查询所有通讯录入驻（热门排行）")
    @GetMapping("/ipaEnterListHot")
    public Result<IPage<IpaEnter>> ipaEnterListHot(Integer type,
                                                   @RequestParam(required = false) String name, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit) {
        if (type == 1) {
            if (StringUtils.isEmpty(name)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber).like(IpaEnter::getName, name);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        } else if (type == 2) {
            if (StringUtils.isEmpty(name)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber).like(IpaEnter::getName, name);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        } else if (type == 3) {
            if (StringUtils.isEmpty(name)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber).like(IpaEnter::getName, name);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        }

        Page<IpaEnter> recommendPage = new Page<>(page, limit);
        IPage<IpaEnter> iPage = null;
        return Result.fail(iPage).message("查询失败！数据为空！");
    }


    @ApiOperation(value = "查询所有通讯录入驻（地址）")
    @GetMapping("/ipaEnterListAddress")
    public Result<IPage<IpaEnter>> ipaEnterListAddress(Integer type,
                                                       @RequestParam(required = false) String address, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit) {
        if (type == 1) {
            if (StringUtils.isEmpty(address)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber).like(IpaEnter::getAddress, address);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        } else if (type == 2) {
            if (StringUtils.isEmpty(address)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber).like(IpaEnter::getAddress, address);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        } else if (type == 3) {
            if (StringUtils.isEmpty(address)) {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            } else {
                LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(IpaEnter::getStart, 1).orderByDesc(IpaEnter::getNumber).like(IpaEnter::getAddress, address);
                List<IpaEnter> list = ipaEnterService.list(wrapper);

                Page<IpaEnter> recommendPage = new Page<>(page, limit);
                IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
                return Result.ok(iPage);
            }
        }

        Page<IpaEnter> recommendPage = new Page<>(page, limit);
        IPage<IpaEnter> iPage = null;
        return Result.fail(iPage).message("查询失败！数据为空！");
    }


    @ApiOperation(value = "查询所有通讯录通过")
    @GetMapping("/ipaEnterList")
    public Result<IPage<IpaEnter>> ipaEnterList(@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer limit, @RequestParam(required = false) String carname) {

        if (StringUtils.isEmpty(carname)) {
//            LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
//            wrapper.eq(IpaEnter::getStart, 1);
            QueryWrapper<IpaEnter> wrapper = new QueryWrapper<>();
            wrapper.ne("start",2);
            Page<IpaEnter> recommendPage = new Page<>(page, limit);
//            IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
            IPage<IpaEnter> iPage = ipaEnterService.page(recommendPage, wrapper);
            return Result.ok(iPage);
        } else if (!StringUtils.isEmpty(carname)) {
//            LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
//            wrapper.eq(IpaEnter::getStart, 1).like(IpaEnter::getName, name);
            QueryWrapper<IpaEnter> wrapper = new QueryWrapper<>();
            wrapper.ne("start",2).like("name", carname);;
//            wrapper.ne(IpaEnter::getStart, 2).like(IpaEnter::getName, carname);
            Page<IpaEnter> recommendPage = new Page<>(page, limit);
            IPage<IpaEnter> iPage;
            iPage = ipaEnterService.page(recommendPage, wrapper);
            return Result.ok(iPage);
        }
        Page<IpaEnter> recommendPage = new Page<>(page, limit);
        IPage<IpaEnter> iPage = null;
        return Result.fail(iPage).message("暂无数据！！！");

    }

    @ApiOperation(value = "查询通讯录详情")
    @GetMapping("/ipaEnter/{id}")
    public Result<IpaEnter> ipaEnterById(@PathVariable Integer id) {

        String s = AuthContextUtil.get();

        LambdaQueryWrapper<IpaCollect> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IpaCollect::getAppletUserId, Integer.valueOf(s)).eq(IpaCollect::getIpaId, id);
        IpaCollect one = ipaCollectService.getOne(wrapper);

        IpaEnter byId = ipaEnterService.getById(id);
        byId.setNumber(byId.getNumber() + 1);
        if (one != null) {
            byId.setCollect(1);
            return Result.ok(byId);

        }else if (one == null){
            byId.setCollect(0);
            return Result.ok(byId);
        }
        return Result.fail();
    }


    @ApiOperation(value = "入驻通讯录圈子")
    @PostMapping("saveIpaEnter")
    public Result saveIpaEnter(@RequestBody IpaEnter ipaEnter) {
        String s = AuthContextUtil.get();
        LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IpaEnter::getAppletUserId, Integer.valueOf(s));
        IpaEnter byId = ipaEnterService.getOne(wrapper);
        if (byId != null) {

            LambdaQueryWrapper<IpaEnter> wrapper1 = new LambdaQueryWrapper<>();
            wrapper1.eq(IpaEnter::getAppletUserId, Integer.valueOf(s));
            IpaEnter byId111 = ipaEnterService.getOne(wrapper1);

            byId111.setStart(0);
            byId111.setName(ipaEnter.getName());
            byId111.setPhone(ipaEnter.getPhone());
            byId111.setAddress(ipaEnter.getAddress());
            byId111.setWechatid(ipaEnter.getWechatid());
            byId111.setEmail(ipaEnter.getEmail());
            byId111.setTitle(ipaEnter.getTitle());
            byId111.setCompany(ipaEnter.getCompany());
            byId111.setAvatar(ipaEnter.getAvatar());
            byId111.setUpdateTime(LocalDateTime.now());

            AppletUser byId1 = appletUserService.getById(Integer.valueOf(s));
            byId1.setAvatar(ipaEnter.getAvatar());
            byId1.setNickName(ipaEnter.getName());


            boolean save = ipaEnterService.updateById(byId111);
            if (save) {
                return Result.ok().message("修改成功");
            }
            return Result.fail().message("修改失败");

        } else if (byId == null) {

            ipaEnter.setAppletUserId(Integer.valueOf(s));
            ipaEnter.setStart(0);
            ipaEnter.setCreateTime(LocalDateTime.now());
            ipaEnterService.save(ipaEnter);

            AppletUser byId1 = appletUserService.getById(Integer.valueOf(s));
            byId1.setAvatar(ipaEnter.getAvatar());
            byId1.setNickName(ipaEnter.getName());
//            LambdaQueryWrapper<IpaEnter> wrapper1 = new LambdaQueryWrapper<>();
//            wrapper1.eq(IpaEnter::getAppletUserId,Integer.valueOf(s));
//            IpaEnter byId111 = ipaEnterService.getById(wrapper1);
//
//        byId111.setName(ipaEnter.getName());
//        byId111.setPhone(ipaEnter.getPhone());
//        byId111.setAddress(ipaEnter.getAddress());
//        byId111.setWechatid(ipaEnter.getWechatid());
//        byId111.setEmail(ipaEnter.getEmail());
//        byId111.setTitle(ipaEnter.getTitle());
//        byId111.setCompany(ipaEnter.getCompany());
//        byId111.setAvatar(ipaEnter.getAvatar());
//        byId111.setUpdateTime(LocalDateTime.now());

            boolean save = ipaEnterService.updateById(ipaEnter);
            if (save) {
                return Result.ok().message("修改成功");
            }
            return Result.fail().message("修改失败");
        }

        return Result.fail().message("暂无数据！！！");
    }

    @ApiOperation(value = "通过入驻通讯录")
    @PostMapping("updateIpaEnterStart")
    public Result updateIpaEnterStart(@RequestBody IpaEnter ipaEnter) {

        ipaEnter.setStart(1);
        boolean byId = ipaEnterService.updateById(ipaEnter);

        Integer appletUserId = ipaEnter.getAppletUserId();
        AppletUser byId1 = appletUserService.getById(appletUserId);
        byId1.setEnter(1);
        boolean byId2 = appletUserService.updateById(byId1);

        if (byId) {
            return Result.ok().message("通过审核");
        }
        return Result.fail().message("未通过审核");
    }


    @ApiOperation(value = "删除通讯录入驻")
    @PostMapping("delectIpaEnter")
    public Result delectIpaEnter(@RequestBody IpaEnter ipaEnter) {
//        String s = AuthContextUtil.get();
        boolean b = ipaEnterService.removeById(ipaEnter.getId());

        if (b) {
            return Result.ok().message("删除成功");
        }
        return Result.fail().message("删除失败");
    }


    @ApiOperation(value = "修改通讯录入驻信息")
    @PostMapping("updateIpaEnter")
    public Result<IpaEnter> updateIpaEnter(@RequestBody IpaEnter ipaEnter) {
        String s = AuthContextUtil.get();

        LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IpaEnter::getAppletUserId,Integer.valueOf(s));
        IpaEnter one = ipaEnterService.getOne(wrapper);



        one.setUpdateTime(LocalDateTime.now());
        boolean update = ipaEnterService.updateById(one);

        if (update) {

            LambdaQueryWrapper<AppletUser> wrapper1 = new LambdaQueryWrapper<>();
            wrapper1.eq(AppletUser::getId, Integer.valueOf(s));
            AppletUser byId = appletUserService.getById(wrapper1);

            byId.setAvatar(ipaEnter.getAvatar());
            byId.setNickName(ipaEnter.getName());

            appletUserService.updateById(byId);
            return Result.ok(ipaEnter).message("修改成功");
        }
        return Result.fail(ipaEnter).message("修改失败");
    }

    @ApiOperation(value = "添加通讯录收藏")
    @PostMapping("/collectIpaEnter")
    public Result<IpaCollect> collectIpaEnter(@RequestBody IpaEnter ipaEnter) {

        String s = AuthContextUtil.get();

        LambdaQueryWrapper<IpaCollect> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IpaCollect::getIpaId, ipaEnter.getId()).eq(IpaCollect::getAppletUserId, Integer.valueOf(s));
        IpaCollect one = ipaCollectService.getOne(wrapper);

        if (one!=null){
            return Result.ok(one);
        }else {
            IpaCollect produceCollect = new IpaCollect();
            produceCollect.setCreateTime(LocalDateTime.now());
            produceCollect.setIpaId(ipaEnter.getId());
            produceCollect.setAppletUserId(Integer.valueOf(s));
            boolean save = ipaCollectService.save(produceCollect);

            if (save) {
                return Result.ok(produceCollect).message("添加成功");
            } else {
                return Result.ok(produceCollect).message("添加失败");
            }
        }
    }

    @ApiOperation(value = "删除通讯录收藏")
    @PostMapping("delectIpaEnterCollect")
    public Result delectIpaEnterCollect(@RequestBody IpaEnter ipaEnter) {
        String s = AuthContextUtil.get();

        LambdaQueryWrapper<IpaCollect> wrapper = new LambdaQueryWrapper<>();
        Integer id = ipaEnter.getId();
        wrapper.eq(IpaCollect::getIpaId,id).eq(IpaCollect::getAppletUserId, Integer.valueOf(s));
        boolean b = ipaCollectService.remove(wrapper);

        if (b) {
            return Result.ok().message("删除成功");
        }
        return Result.fail().message("删除失败");
    }


    @ApiOperation("当前用户的通讯录")
    @GetMapping("getIpaEnterOne")
    public Result<IpaEnter> getIpaEnterOne() {
        String s = AuthContextUtil.get();

        LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IpaEnter::getAppletUserId, Integer.valueOf(s));
        IpaEnter one = ipaEnterService.getOne(wrapper);
        return Result.ok(one);
    }


    @ApiOperation(value = "excel导出")
    @PostMapping("/downloadExcel")
    @JsonIgnoreProperties({"customPalette"})
    public void downloadExcel(HttpServletResponse response) throws IOException {

        List<IpaDown> list = new ArrayList<>();
        //Mybatis Plus自带的list方法，获取所有数据封装到实体类中返回实体类的列表

        //获取数据库数据
//        LambdaQueryWrapper<IpaEnter> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(IpaEnter::getStart, 1);
        List<IpaEnter> list1 = ipaEnterService.list();
        if (list1.isEmpty()) {
            list1 = new ArrayList<>();
        }

        //通过循环将所得到的数据封装到PromptInformationDown 中
//        Long num = Long.valueOf(0);
        //新增数据行，并且设置单元格格式
        int rowNum = 1;

//        list1.stream().forEach(a -> {
        for (int i = 0; i < list1.size(); i++) {
            IpaDown d = new IpaDown();

            d.setId(Long.valueOf(i + 1));
            d.setName(list1.get(i).getName());
            d.setAddress(list1.get(i).getAddress());
            d.setWechatID(list1.get(i).getWechatid());
            d.setEmail(list1.get(i).getEmail());
            d.setTitle(list1.get(i).getTitle());
            d.setCompany(list1.get(i).getCompany());
            d.setPhone(list1.get(i).getPhone());

            if (list1.get(i).getStart() == 2) {
                d.setStart("未申请");
            } else if (list1.get(i).getStart() == 0) {
                d.setStart("申请中");
            } else if (list1.get(i).getStart() == 1) {
                d.setStart("已入驻");
            }
            d.setCreateTime(list1.get(i).getCreateTime());
            //将装好的实体类添加进总list中
            list.add(d);
        }


        // 设置文本内省
        response.setContentType("application/vnd.ms-excel");
        // 设置字符编码
        response.setCharacterEncoding("utf-8");
        // 设置响应头
        //设置要导出的文件名
        String fileName = "D:/file/" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM-ddHHmmss")) + "通讯录注册统计.xls";
//        response.setHeader("Content-disposition", "attachment;filename="+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM-ddHHmmss")) + "用户注册统计.xls");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        EasyExcel.write(response.getOutputStream(), IpaDown.class)
                .sheet("消息列表").doWrite(list);

    }
}

